#include <dbg.h>

#include <cassert>

using namespace std;

class Solution {
public:
    int maxConsecutiveAnswers(string answerKey, int k) {
        int res = 0;
        int left = 0;
        vector<int> cnt(2, 0);  // 0: T, 1: F
        for (int right = 0; right < answerKey.size(); ++right) {
            ++cnt[answerKey[right] == 'F'];
            while (min(cnt[0], cnt[1]) > k) {
                --cnt[answerKey[left] == 'F'];
                ++left;
            }
            res = max(res, right - left + 1);
        }
        return res;
    }
};

int main() {
    Solution s;

    string answerKey1 = "TTFF";
    string answerKey2 = "TFFT";
    string answerKey3 = "TTFTTFTT";

    int k1 = 2;
    int k2 = 1;
    int k3 = 1;

    assert(s.maxConsecutiveAnswers(answerKey1, k1) == 4);
    assert(s.maxConsecutiveAnswers(answerKey2, k2) == 3);
    assert(s.maxConsecutiveAnswers(answerKey3, k3) == 5);

    return 0;
}